home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 25 / Mac Magazin and MacEasy Magazine CD - Issue 25.iso / Online / Turbo Mail Processor / Marionet 1.1.1 Trial Version ƒ / Read the License before Opening / Marionet Tutorial < prev    next >
Text File  |  1996-05-22  |  16KB  |  343 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                                  Marionet Trial Version Tutorial
  10.  
  11.  
  12. Before continuing, you should read the "Marionet TV Instructions" document. You'll also need a TCP/IP connection to the internet. Lastly, we assume some basic familiarity with HyperCard or SuperCard including the ability to create new stacks or projects; to write simple scripts; and to install and use XCMDs.
  13.  
  14. In this tutorial, you will create a simple program that sends email messages. You will learn how to begin a session, make a session synchronous (one task at a time), send an email message, check for errors, end a session, and quit Marionet. With the finished program you will be able to subscribe to the Marionet Mailing list where other users of Marionet discuss the product.
  15.  
  16. After completing this tutorial and exploring the included finished examples, you should have a good understanding of how to develop with Marionet. While these are all simple examples, the process is roughly the same whether you are sending an email message, downloading a file, searching a gopher server, getting the html for a web page, posting a message to a newsgroup, or any number of other tasks you can perform with Marionet.
  17.  
  18.  
  19. Constructing the Stack or Project
  20.  
  21. Depending on whether you are using HyperCard or SuperCard, you'll need to make a new stack or project. A single card with 5 card fields and a card button named "Send" are all that will be required. Below is a screen shot of a HyperCard stack which illustrates how the finished card might look. It is not important to recreate, exactly, the card shown below - just make something similar.
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. You'll need to use ResEdit or a similar program to install the Marionet XCMD into your stack. In the case of SuperCard, you would use the Import Resources option in SuperEdit to import the XCMD into your project.
  43.  
  44. Now we'll look at the individual Marionet commands we'll be using for this project.
  45.  
  46.  
  47. The BeginSession and EndSession Commands
  48.  
  49. Before doing anything with Marionet, you must ensure that it is launched and you must have a session id number. A session id identifies a "thread" or "session" in Marionet. Because you can use Marionet asynchronously, the session id is used to identify individual tasks such as downloading a file or sending an email message. A single command, BeginSession, is used to request session ids and to take care of the details of launching Marionet as needed.
  50.  
  51. The BeginSession command has the following syntax:
  52.  
  53.   Marionet "BeginSession"
  54.  
  55. The result of this command will contain two lines. The first line will be either OK or ERROR. If the first line is OK then the second line will contain a session id. If the first line is ERROR, then the second line will contain an error message. When you call BeginSession, the Marionet XCMD will automatically check to see if Marionet is running. If Marionet is not running, the XCMD will search your local hard disks for Marionet and launch it.
  56.  
  57. NOTE: Be aware that BeginSession will launch the first copy of Marionet it finds which may or may not be the trial version (you may have previously downloaded the earlier public beta of Marionet or you may have purchased the full product already). The full product includes an application called Marionet Manager which allows you to specify which copy of Marionet to use, including copies running on workgroup servers that you may be connected to.
  58.  
  59. Once you have a session id, you'll generally want to save it for future reference, perhaps in a global variable. When you are finished with a session, you'll need to dispose of it — the EndSession command is used for this purpose:
  60.  
  61.   Marionet "EndSession", sessionID
  62.  
  63. Here is a simple function which begins and ends sessions:
  64.  
  65.   Function ManageSession sessionID
  66.     Global gErrorMessage
  67.  
  68.     IF sessionID is empty THEN -- begin a new session
  69.       Marionet "BeginSession"
  70.       put the result into SessionID
  71.       IF line 1 of SessionID is "OK" THEN -- new session, marionet is running
  72.         delete line 1 of SessionID -- clean up
  73.       ELSE
  74.         put line 2 of SessionID into gErrorMessage -- save error message
  75.         put empty into SessionID
  76.       END IF
  77.  
  78.     ELSE Marionet "EndSession", SessionID -- end the session
  79.  
  80.     Return SessionID
  81.  
  82.   End ManageSession
  83.  
  84. If ManageSession is not passed a value, it tries to create a new session. If it is successful in creating a session, it returns the session id. If it cannot create a session, it returns empty and the global variable gErrorMessage will contain the error message. 
  85.  
  86. If ManageSession is passed a session id, it ends that session - you would ignore the return value in this case.
  87.  
  88.  
  89. The SessionSet Command
  90.  
  91. Marionet sessions have various properties such as sync (synchronous), name, etc. The SessionSet command is used to set these properties. The syntax for SessionSet is:
  92.  
  93.   Marionet "SessionSet", SessionID, PropertyName, PropertyValue
  94.  
  95. For this example, we'll be using a synchronous session (for an example of the scripting required for an asynchronous session, refer to one of the included example programs). Besides the obvious property values for the Sync property (true|false) others are available such as "cursor". We'll be using the cursor property value in this example. The value "cursor" is the same as setting the sync property to true except that it also causes a beachball cursor to spin whenever a command is executing in the session.
  96.  
  97. Using the ManageSession function above, a handler that created a new synchronous session might look like this:
  98.  
  99. On mouseUp
  100.   Global gSessionID, gErrorMessage
  101.  
  102.   IF gSessionID is empty THEN -- is there already a session available?
  103.  
  104.     put ManageSession() into gSessionID
  105.     IF gSessionID is empty THEN -- an error occurred
  106.       answer gErrorMessage -- display the error
  107.       exit mouseUp -- abort
  108.     END IF
  109.  
  110.     Marionet "SessionSet", gSessionID, "sync", "cursor" -- set the sync property
  111.  
  112.     dosomeMarionetcommand....
  113.  
  114.     get ManageSession(gSessionID) -- end the session
  115.     put empty into gSessionID
  116.  
  117.   END IF
  118.  
  119. End mouseUp
  120.  
  121.  
  122. The SendMail Command
  123.  
  124. One of the many internet tasks that Marionet can perform is sending email. The SendMail command is used for this purpose. Marionet also includes a number of commands for managing email - counting messages, downloading messages, deleting messages, etc. which are discussed in the full product's manual.
  125.  
  126. Here is the syntax for SendMail:
  127.  
  128.  Marionet "SendMail", sessionID, serverName, from, toList, messageText {,errorVar}
  129.  
  130. The braces around the errorVar parameter denote a synchronous parameter. Synchronous parameters are simply variables that will be filled in by Marionet for use after the call is completed. In other words they are a way for Marionet to return values to you in addition to "the result". 
  131.  
  132. In SuperCard, synchronous parameters are declared local variables which are passed by reference. In HyperCard (and other XCMD environments), they are global variables passed as quoted strings. Here are some examples to illustrate:
  133.  
  134. SuperCard:
  135.  
  136.   on MailSender sessionID, serverName, from, to, messageText
  137.     local errorVar
  138.  
  139.     SendMail sessionID, serverName, from, to, messageText, @errorVar
  140.     get the result
  141.     if line 1 of it is not "OK" then.....
  142.  
  143.     If line 1 of errorVar is not "OK" then....
  144.  
  145.   end MailSender
  146.  
  147.  
  148. HyperCard:
  149.  
  150.   on MailSender sessionID, serverName, from, to, messageText
  151.     global gErrorVar
  152.  
  153.     SendMail sessionID, serverName, from, to, messageText, "gErrorVar"
  154.     get the result
  155.     if line 1 of it is not "OK" then.....
  156.  
  157.     If line 1 of gErrorVar is not "OK" then....
  158.  
  159.   end MailSender
  160.  
  161.  
  162. The other parameters to SendMail are as follows:
  163. SessionID: a valid session id as discussed previously.
  164. ServerVersion: the name or ip address of your mail server. For example: cts.com
  165. From: your email address. For example: yourName@somewhere.com
  166. ToList: One or more email addresses, separated by commas, to send the message too.
  167. MessageText: The actual message to send. You must include any header information you want included with the message in addition to the actual message text. For example, a subject line:
  168.  
  169.   Subject: the subject of this message
  170.  
  171.   the actual message here
  172.  
  173. There must be a blank line separating any header information from the actual message. At a minimum, you should always include a subject for the header. A formal discussion of message headers is beyond the scope of this tutorial.
  174.  
  175. Building on the ManageSession and mouseUp handlers shown previously, here is a script which sends a simple message to a single address (for HyperCard):
  176.  
  177. On mouseUp
  178.   Global gSessionID, gErrorMessage, gErrorVar
  179.  
  180.   IF gSessionID is empty THEN -- is there already a session available?
  181.  
  182.     put ManageSession() into gSessionID
  183.     IF gSessionID is empty THEN -- an error occurred
  184.       answer gErrorMessage -- display the error
  185.       exit mouseUp -- abort
  186.     END IF
  187.  
  188.     Marionet "SessionSet", gSessionID, "sync", "cursor" -- set the sync property
  189.  
  190.     put "mail@server" into mailServer
  191.     put "myName@mydomain.com" into myAddress
  192.     put "theirName@theirdomain.com" into theirAddress
  193.     put "Subject: big test" & return & return & "Hello World!" into messageText
  194.  
  195.     Marionet "SendMail", gSessionID, mailServer, myAddress, theirAddress, messageText, "gErrorVar"
  196.     get the result -- XCMD errors
  197.     IF (line 1 of it) is "ERROR" THEN
  198.       answer line 2 of it -- display error message
  199.     ELSE IF (line 1 of gErrorVar) is "ERROR" THEN -- internet error of some sort
  200.       answer line 2 of gErrorVar
  201.     END IF
  202.  
  203.     get ManageSession(gSessionID) -- end the session
  204.     put empty into gSessionID
  205.  
  206.   END IF
  207.  
  208. End mouseUp
  209.  
  210.  
  211.  
  212. The Quit Command
  213.  
  214. When it is time to quit your program, it is your responsibility as the developer to quit Marionet. The Quit command syntax is simply:
  215.  
  216.   Marionet "Quit"
  217.  
  218. Marionet will not quit if the quit command comes from another machine over the network, if the user has configured Marionet not to quit using the Marionet Manager application, or if any sessions are currently active (you can call Marionet "ListSessions" at anytime to get a list of session ids in the result). For these reasons, you don't need to check for errors with the Quit command, just call it and Marionet will Quit if appropriate.
  219.  
  220.  
  221. Bringing Everything Together
  222.  
  223. Ok, you should now have a good overview of how to develop with Marionet and an understanding of the commands we'll be using. It's time to build the Send Mail program.
  224.  
  225. If you have not already constructed the stack or project discussed at the beginning of this tutorial, now's the time to do it.
  226.  
  227. First, name the individual fields in the stack or project as follows (reading from the top of the card down):
  228.  
  229.   MailServer
  230.   MailAddress
  231.   ToAddress
  232.   Subject
  233.   Message
  234.  
  235. Now, we'll modify the send mail example script shown previously to refer to those fields (for HyperCard):
  236.  
  237. On mouseUp
  238.   Global gSessionID, gErrorMessage, gErrorVar
  239.  
  240.   IF gSessionID is empty THEN -- is there already a session available?
  241.  
  242.     put ManageSession() into gSessionID
  243.     IF gSessionID is empty THEN -- an error occurred
  244.       answer gErrorMessage -- display the error
  245.       exit mouseUp -- abort
  246.     END IF
  247.  
  248.     Marionet "SessionSet", gSessionID, "sync", "cursor" -- set the sync property
  249.  
  250.     put card field "MailServer" into mailServer
  251.     put card field "MailAddress" into myAddress
  252.     put card field "ToAddress" into theirAddress
  253.     put card field "Subject" into subject
  254.     put "Subject: " & card field "Subject" into subject
  255.  
  256.     Marionet "SendMail", gSessionID, mailServer, myAddress, theirAddress, messageText, "gErrorVar"
  257.     get the result -- XCMD errors
  258.     IF (line 1 of it) is "ERROR" THEN
  259.       answer line 2 of it -- display error message
  260.     ELSE IF (line 1 of gErrorVar) is "ERROR" THEN -- internet error of some sort
  261.       answer line 2 of gErrorVar
  262.     END IF
  263.  
  264.     get ManageSession(gSessionID) -- end the session
  265.     put empty into gSessionID
  266.  
  267.   END IF
  268.  
  269. End mouseUp
  270.  
  271.  
  272. If you are using SuperCard, modify the above handler so that the ErrorVar parameter is declared as a local and is passed by reference to SendMail as discussed previously. The script should look like this for SuperCard (note the bold face type to indicate the differences):
  273.  
  274. On mouseUp
  275.   Global gSessionID, gErrorMessage
  276.   LOCAL errorVar
  277.  
  278.   IF gSessionID is empty THEN -- is there already a session available?
  279.  
  280.     put ManageSession() into gSessionID
  281.     IF gSessionID is empty THEN -- an error occurred
  282.       answer gErrorMessage -- display the error
  283.       exit mouseUp -- abort
  284.     END IF
  285.  
  286.     Marionet "SessionSet", gSessionID, "sync", "cursor" -- set the sync property
  287.  
  288.     put card field "MailServer" into mailServer
  289.     put card field "MailAddress" into myAddress
  290.     put card field "ToAddress" into theirAddress
  291.     put card field "Subject" into subject
  292.     put "Subject: " & card field "Subject" into subject
  293.  
  294.     Marionet "SendMail", gSessionID, mailServer, myAddress, theirAddress, messageText, @errorVar
  295.     get the result -- XCMD errors
  296.     IF (line 1 of it) is "ERROR" THEN
  297.       answer line 2 of it -- display error message
  298.     ELSE IF (line 1 of errorVar) is "ERROR" THEN -- internet error of some sort
  299.       answer line 2 of errorVar
  300.     END IF
  301.  
  302.     get ManageSession(gSessionID) -- end the session
  303.     put empty into gSessionID
  304.  
  305.   END IF
  306.  
  307. End mouseUp
  308.  
  309.  
  310. Place the mouseUp handler into the Send button in the stack or project. This handler takes care of all the details of launching Marionet, creating a new session, setting the session to synchronous, constructing an email message, sending the message, and terminating the session. It also performs some simple error checking.
  311.  
  312. Next, take the ManageSession handler shown previously and place it into the stack or; for SuperCard; the window script.
  313.  
  314. The only thing remaining is to take care of quitting Marionet when your program is quit. In HyperCard, add the following handler to the stack script of your stack:
  315.  
  316.   On closeStack
  317.     Marionet "Quit"
  318.     pass closeStack
  319.   End closeStack
  320.  
  321. For SuperCard, add the following handler to the script of the window:
  322.  
  323.   On closeWindow
  324.     Marionet "Quit"
  325.     pass closeWindow
  326.   End closeWindow
  327.  
  328.  
  329. Try It Out!
  330.  
  331. Try sending some email to yourself. Enter your mail server name in the Mail Server field. If you don't know the name of the mail server, it's often the same as your domain name from your email address (the part after the @ symbol). Next enter your email address in both of the address fields, a subject in the subject field, and a message in the message field. Then click the send button. Assuming your machine is connected to the internet, the message should be sent to your mail server. Use your normal email program to retrieve it.
  332.  
  333. If the first test worked, then it's time to try sending a message to someone else — how about us? Allegiant maintains a mailing list to facilitate discussion of Marionet among current users and potential users. It's a great place to ask questions about the product and to learn what others are using it for. To subscribe to the list, address your message to marionet@list.allegiant.com and put the word Subscribe into the SUBJECT line of the message. Leave the body of the message empty. Click the Send button and a short time later a message will arrive in your mail box welcoming you to the mailing list.
  334.  
  335. Thank-you!
  336.  
  337. We hope you have enjoyed this introduction to Marionet and that you've found the Trial Version useful. We look forward to your order when you're ready - the How To Order document contains all the needed contact information for placing your order. Thanks again!
  338.  
  339. P.S. The Marionet 1.1 Trial Version will time-out after 30-days. However, a small number of commands will continue to work. All of the commands used in this Tutorial will continue to work even after the Trial Version has timed-out.
  340.  
  341. Copyright ©1996 Allegiant Technologies, Inc.  All Rights Reserved.  SuperCard is a registered trademark and Marionet and the Allegant “A” logo and logotype are trademarks of Allegiant Technologies, Inc.  Macintosh is a registered trademark and AppleScript and AppleEvents are trademarks of Apple Computer, Inc.  All other product and corporate names may be trademarks or registered trademarks of other companies and are used only for explanation without intent to infringe.
  342.  
  343. REV 1.1  5/22/96  BRM